package registnet.records.summary.freq.source;

import java.util.List;

import registnet.records.DegreeProgram;
import registnet.records.summary.freq.ClassificationFrequency;
import resources.Constants;

public class ClassificationFrequencySource {

	private DegreeProgram degreeProgram;
	private int semester;
	private int year;
	private ClassificationFrequency classificationFrequency;
	
	public ClassificationFrequencySource(DegreeProgram degreeProgram, int semester, int year){
		this.degreeProgram = degreeProgram;
		this.semester = semester;
		this.year = year;
		this.load();
	}
	
	
	public void load(){
		registnet.dao.StudentClassificationPeer scp = new registnet.dao.StudentClassificationPeer();
		List<registnet.dao.StudentClassification> DAOStudentClassifications;
		DAOStudentClassifications = scp.getClassificationsByDegreeProgram(new registnet.dao.DegreeCoursePeer().getDegreeCourseId(this.degreeProgram.getDegreeCode()), this.semester, this.year);
		this.classificationFrequency = new ClassificationFrequency(this.degreeProgram, this.semester, this.year);

		
		for(int i=0; i<DAOStudentClassifications.size(); i++){
			registnet.dao.StudentClassification DAOStudentClassification = DAOStudentClassifications.get(i);
			String classification = Constants.MAP_CLASSIFICATION_KEY.get(DAOStudentClassification.getClassification());
			System.out.println("[check] classification: "+classification);
			this.classificationFrequency.setFrequency(classification, this.classificationFrequency.getFrequency(classification) + 1);
		}
	}
	
	public ClassificationFrequency getClassificationFrequency(){
		return this.classificationFrequency;
	}
	
}
